<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel=stylesheet type=text/css href="css/input.css">
<style type="text/css">
	body{
		background:#dae4fe;
	}
	.td_one{
		text-align:right;
	}
	label{
		margin-left:45px;
		color:red;
	}
</style>
<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script>
	$(function(){
		$("#caname").click(function(){
			var cavalue=$(this).val();
			$("#cavalue").val(cavalue);
		});
		$(".def").click(function(){
			var cid = $("#cid").val();
			var ctid = $("#ctid").val();
			var dPprice = $("#dPprice").val();
			var dPrice = $("#dPrice").val();
			var dStock = $("#dStock").val();
			var caName = $("#caname").val();
			var caValue = $("#cavalue").val();
			$.get("updatecommodity",{cid:cid,ctid:ctid,dPprice:dPprice,dPrice:dPrice,
			dStock:dStock,caName:caName,caValue:caValue},function(v){
				$("#label1").html(v);
			});
		});
	});
	function chongzhi(){
		location.reload();
	}
</script>
</head>
<body>
	<form>
		<table>
			<tr>
				<td class="td_one">商品名：</td>
				<td>
					<select onfocus="this.defaultIndex=this.selectedIndex;" 
							onchange="this.selectedIndex=this.defaultIndex;" id="cid">
						<c:forEach items="${list}" var="sp">
							<c:if test="${list2.get(0).cId eq sp.cId}">
								<option selected="selected" value="${sp.cId}">${sp.cName}</option>
							</c:if>
							<c:if test="${list2.get(0).cId ne sp.cId}">
								<option value="${sp.cId}">${sp.cName}</option>
							</c:if>
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td class="td_one">商品类型：</td>
				<td>
					<select id="ctid">
						<c:forEach items="${list1}" var="leixing">
							<c:if test="${list2.get(0).ctId eq leixing.ctId}">
								<option selected="selected" value="${leixing.ctId}">${leixing.ctName}</option>
							</c:if>
							<c:if test="${list2.get(0).ctId ne leixing.ctId}">
								<option value="${leixing.ctId}">${leixing.ctName}</option>
							</c:if>
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td class="td_one">商品进价：</td>
				<td><input id="dPprice" value="${list2.get(0).dPprice}"></td>
			</tr>
			<tr>
				<td class="td_one">商品售价：</td>
				<td><input id="dPrice" value="${list2.get(0).dPrice}"></td>
			</tr>
			<tr>
				<td class="td_one">商品库存：</td>
				<td><input id="dStock" value="${list2.get(0).dStock}"></td>
			</tr>
			<tr>
				<td class="td_one">独有属性名：</td>
				<td>
					<select id="caname">
						<c:forEach items="${list2}" var="ca">
							<option value="${ca.caValue}">${ca.caName}</option>
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td class="td_one">独有属性值：</td>
				<td><input id="cavalue" value="${list2.get(0).caValue}"></td>
			</tr>
			<tr>
				<td class="td_one">
					<a class="def" href="javascript:void(0)">
						<input type="button" value="修   改">
					</a>
				</td>
				<td><input onclick="chongzhi()" type="button" value="重   置"></td>
			</tr>
		</table>
		<label id="label1"></label>
	</form>
</body>
</html>